using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net.Mime;
using TPTecnicas.MessageProcessor.Common;

namespace TPTecnicas.MessageProcessor.Business
{
    public class Mail : MailMessage , IMessage
    {

		public string Sender { get; set; }

		public string Destinatary { get; set; }

		public string Subject { get; set; }

		public IEnumerable<string> Attachments { get; set; }

		/// <summary>
		/// To whom the email was
		/// </summary>
		public MailAddress ReturnPath;

		/// <summary>
		/// 
		/// </summary>
		public DateTime DeliveryDate;

		/// <summary>
		/// Date when the email was received
		/// </summary>
		public string ReceiveDate;

		/// <summary>
		/// 
		/// </summary>
		public AttachmentCollection MailAttachments { get; set; }


		public Mail()
		{
		}


		public Mail(Pop3.RxMailMessage rxMail)
		{
			//TODO hacer un datamapper o ver si se persiste el mail y hacer una POCO
			if (!String.IsNullOrEmpty(rxMail.Body))
				Body = rxMail.Body;
			else if (!String.IsNullOrEmpty(rxMail.Entities[0].Body))
				Body = rxMail.Entities[0].Body;
			else
				Body = rxMail.Entities[1].Body;

			if (rxMail.Attachments.Count > 0)
				MailAttachments = rxMail.Attachments;
			else if (rxMail.Entities[0].Attachments.Count > 0)
				MailAttachments = rxMail.Entities[0].Attachments;
			else
				MailAttachments = rxMail.Entities[1].Attachments;
		}

	}
}
